<template>
  <div class="masOrder">
    <!-- 短信变动页面 -->
    <!-- 表格部分 -->
    <div class="tableData">
      <el-table style="width: 100%;margin-bottom: 40px" :data="tableData">
        <el-table-column align="center" label="序号" type="index" width="50"></el-table-column>
        <el-table-column align="center" min-width="100" label="订单号">
          <template slot-scope="scope">
            <span>{{scope.row.sms_ordenum.substring(scope.row.sms_ordenum.length - 8)}}</span>
          </template>
        </el-table-column>
        <el-table-column align="center" min-width="160" label="类型" prop="sms_mealname"></el-table-column>
        <el-table-column align="center" label="变动前数量" prop="sms_beforenum_host"></el-table-column>
        <el-table-column align="center" label="变动后数量" prop="sms_afternum_host"></el-table-column>
        <el-table-column align="center" label="变动数量" prop="sms_mealnum"></el-table-column>
        <el-table-column align="center" label="合计金额" prop="sms_mealprice"></el-table-column>
        <el-table-column
          align="center"
          min-width="160"
          :formatter="dateFormat"
          label="时间"
          prop="sms_mealdate"
        ></el-table-column>
        <el-table-column align="center" min-width="150" label="支付方式" prop="sms_mealpayment"></el-table-column>
      </el-table>
    </div>
    <!-- 这个是分页器 -->
    <Pagination
      :total="total"
      :pageIndex="pageIndex"
      :pageSize="pageSize"
      @handleSizeChange="handleSizeChange"
      @handleCurrentChange="handleCurrentChange"
    ></Pagination>
  </div>
</template>

<script>
import Pagination from "@/components/Pagination";
export default {
  data() {
    return {
      // 表单数据
      form: {
        payType: "",
        payWay: "",
        payTime: ""
      },
      // 表格数据
      tableData: [],
      // 总金额
      totalMoney: 0,
      // 分页器的数据
      total: 0, // 总条数
      pageIndex: 1, // 当前页
      pageSize: 10, // 每页数量
      // 当前页订单数
      orderLength: "0",
      // 身份令牌
      myToken: ""
    };
  },
  components: { Pagination },
  methods: {
    // 获取订单数据的方法
    getOrderData() {
      this.$api
        .getSmsChangeList(this.pageIndex, this.pageSize, this.myToken)
        .then(res => {
          if (res.succeed) {
            const { dataList, total } = res.values;
            this.total = total;
            if (dataList == null) {
              this.tableData = dataList;
              return;
            }
            this.tableData = dataList.map(v => {
              return {
                ...v
              };
            });
          }
        });
    },
    //时间格式化
    dateFormat: function(row, column) {
      var date = row[column.property];
      if (date == undefined) {
        return "";
      }
      return this.$moment(date).format("YYYY-MM-DD HH:mm:ss");
    },
    // 分页器的方法
    handleSizeChange(val) {
      this.pageSize = val;
      this.getOrderData();
    },
    handleCurrentChange(val) {
      this.pageIndex = val;
      this.getOrderData();
    }
  },
  mounted() {
    // 获取令牌
    this.myToken = sessionStorage.getItem("myToken");
    // 获取订单列表,初始化列表
    this.getOrderData();
  }
};
</script>

<style lang="less" scoped>
@deep: ~">>>";
.masOrder {
  background-color: #fff;
  padding: 20px;
  .search {
    margin-bottom: 20px;
  }
  // 表格表头
  .tableData @{deep} .el-table th {
    background-color: #fafafa;
    color: #252525;
    font-weight: 100;
  }
}
</style>